package com.hiyee.cart.controller;

import com.hiyee.annotation.CreateEmptyCart;
import com.hiyee.api.controller.BaseController;
import com.hiyee.api.controller.cart.CartControllerApi;
import com.hiyee.cart.service.CartService;
import com.hiyee.pojo.auth.LoginCustomer;
import com.hiyee.pojo.bo.CartAddBO;
import com.hiyee.pojo.bo.CartDeleteBO;
import com.hiyee.pojo.bo.CartUpdateBO;
import com.hiyee.pojo.vo.CartAddVO;
import com.hiyee.response.ResponseJsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CartController extends BaseController implements CartControllerApi {

    @Autowired
    private CartService cartService;

    @Override
    @CreateEmptyCart
    public ResponseJsonResult getTotalNum(LoginCustomer loginCustomer) {
        return this.success(cartService.getCartNum(loginCustomer.getCustomerId()));
    }

    @Override
    public ResponseJsonResult add(CartAddBO cartAddBO, LoginCustomer loginCustomer) {
        CartAddVO cartAddVO = cartService.add(cartAddBO, loginCustomer.getCustomerId());
        return this.success(cartAddVO);
    }

    @Override
    public ResponseJsonResult getList() {
        return this.success(cartService.getList());
    }

    @Override
    public ResponseJsonResult update(CartUpdateBO cartUpdateBO) {
        return this.success(cartService.update(cartUpdateBO));
    }

    @Override
    public ResponseJsonResult delete(CartDeleteBO cartDeleteBO) {
        return this.success(cartService.delete(cartDeleteBO));
    }

    @Override
    public ResponseJsonResult checkout() {
        return this.success(cartService.checkout());
    }
}
